package com.googlecode.imanager.client.style;

import java.io.Serializable;

import com.googlecode.imanager.client.bridge.style.IOpacity;

/**
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public class Opacity implements IOpacity, Serializable {

    private static final long serialVersionUID = 1L;
    
    public static final Opacity EMPTY_OPACITY = new Opacity(1);

    private float value;

    public Opacity(double value) {
        super();
        
        if (value < 0){
            value = 0;
        }
        else if (value > 1){
            value = 1;
        }
        
        this.value = (float) value;
    }

    public float getValue() {
        return value;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this){
            return true;
        }
        if (obj instanceof Opacity){
            return ((Opacity) obj).value == value;
        }
        return false;
    }

    @Override
    public int hashCode() {
        return Float.floatToIntBits(value);
    }

    @Override
    public String toString() {
        return "Opacity[alpha=" + value + "]";
    }
    
}
